﻿namespace PortableRiotGames.Interfaces.League
{
    using Newtonsoft.Json;
    using PortableRiotGames.Infrastructure;
    using PortableRiotGames.Infrastructure.Converters;
    using System;
    using System.Collections.Generic;

    [JsonObject(MemberSerialization.OptIn)]
    [JsonConverter(typeof(JsonGetLeaguesResponseConverter))]
    public sealed class GetLeaguesResponse : ResponseBase
    {
        public List<GetLeaguesResponseTeam> Teams { get; set; }
    }

    [JsonObject(MemberSerialization.OptIn)]
    public sealed class GetLeaguesResponseEntry
    {
        [JsonProperty("isFreshBlood")]
        public bool IsFreshBlood { get; set; }

        [JsonProperty("isHotStreak")]
        public bool IsHotStreak { get; set; }

        [JsonProperty("isInactive")]
        public bool IsInactive { get; set; }

        [JsonProperty("isVeteran")]
        public bool IsVeteran { get; set; }

        [JsonProperty("lastPlayed")]
        [JsonConverter(typeof(JsonDateTimeMiliConverter))]
        public DateTime LastPlayed { get; set; }

        [JsonProperty("leagueName")]
        public string LeagueName { get; set; }

        [JsonProperty("leaguePoints")]
        public int LeaguePoints { get; set; }

        [JsonProperty("miniSeries")]
        public GetLeaguesResponseMiniSeries MiniSeries { get; set; }

        [JsonProperty("playerOrTeamId")]
        public string PlayerOrTeamId { get; set; }

        [JsonProperty("playerOrTeamName")]
        public string PlayerOrTeamName { get; set; }

        [JsonProperty("queueType")]
        [JsonConverter(typeof(JsonRankedQueueConverter))]
        public RankedQueue QueueType { get; set; }

        [JsonProperty("rank")]
        public string Rank { get; set; }

        [JsonProperty("tier")]
        public string Tier { get; set; }

        [JsonProperty("wins")]
        public int Wins { get; set; }
    }

    [JsonObject(MemberSerialization.OptIn)]
    public sealed class GetLeaguesResponseMiniSeries
    {
        /// <summary>
        /// Number of losses.
        /// </summary>
        [JsonProperty("losses")]
        public int Losses { get; set; }

        /// <summary>
        /// Progress
        /// </summary>
        [JsonProperty("progress")]
        public string Progress { get; set; }

        /// <summary>
        /// Target.
        /// </summary>
        [JsonProperty("target")]
        public int Target { get; set; }

        /// <summary>
        /// Time left to play.
        /// </summary>
        [JsonProperty("timeLeftToPlayMillis")]
        [JsonConverter(typeof(JsonTimeSpanMiliSecondsConverter))]
        public TimeSpan TimeLeftToPlay { get; set; }

        /// <summary>
        /// Number of wins.
        /// </summary>
        [JsonProperty("wins")]
        public int Wins { get; set; }
    }

    [JsonObject(MemberSerialization.OptIn)]
    public sealed class GetLeaguesResponseTeam
    {
        [JsonProperty("entries")]
        public List<GetLeaguesResponseEntry> Entries { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("queue")]
        [JsonConverter(typeof(JsonRankedQueueConverter))]
        public RankedQueue Queue { get; set; }

        public string TeamID { get; set; }

        [JsonProperty("tier")]
        [JsonConverter(typeof(JsonEnumUpperStringConverter<RankedTier>))]
        public RankedTier Tier { get; set; }
    }
}